package toolib.util;

import java.awt.DisplayMode;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;


public class GraphicsUtil {
	
	public static final GraphicsConfiguration defaultConfiguration () {
		return defaultDevice ().getDefaultConfiguration ();
	}
	
	public static final GraphicsConfiguration configuration (int theScreenId) {
		return device (theScreenId).getDefaultConfiguration ();
	}
	
	public static final GraphicsDevice defaultDevice () {
		return GraphicsEnvironment.getLocalGraphicsEnvironment ().getDefaultScreenDevice ();
	}
	
	public static final GraphicsDevice device (int theScreenId) {
		return GraphicsEnvironment.getLocalGraphicsEnvironment ().getScreenDevices ()[theScreenId];
	}
	
	public static final int defaultScreenHeight () {
		return defaultDevice ().getDisplayMode ().getHeight ();
	}
	
	public static final int screenHeight (int theScreenId) {
		return device (theScreenId).getDisplayMode ().getHeight ();
	}
	
	public static final int defaultScreenWidth () {
		return defaultDevice ().getDisplayMode ().getWidth ();
	}
	
	public static final int screenWidth (int theScreenId) {
		return device (theScreenId).getDisplayMode ().getWidth ();
	}
	
	public static final void setDefaultMode (int theWidth, int theHeight, int theResolution, int theRefreshRate) {
		defaultDevice ().setDisplayMode (new DisplayMode (theWidth, theHeight, theResolution, theRefreshRate));
	}
	
	public static final void setDefaultFullScreen (Window theWindow, boolean theFullScreenStatus) {
		setFullScreen (0, theWindow, theFullScreenStatus);
	}
	
	public static final void setFullScreen (int theScreenId, Window theWindow, boolean theFullScreenStatus) {
		GraphicsDevice d = device (theScreenId);
		
		if (d.isFullScreenSupported ()) {
			try {
				if (theFullScreenStatus) {
					d.setFullScreenWindow (theWindow);
				}else{
					d.setFullScreenWindow (null);
				}
			}catch (Exception e) {
			}
		}
	}
}